import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:get/get.dart';

// 安全服务
class SercureService extends GetxService {
  // 安全服务
  static SercureService get to => Get.find();

  // 安全存储
  final _storage = const FlutterSecureStorage();

  // 用于头像更新的index
  static const String _avatarUpdateIndex = 'avatar_update_index';

  // 存储头像更新的index
  Future<bool> saveAvatarUpdateIndex(String uid, int index) {
    return _storage
        .write(key: '${_avatarUpdateIndex}_$uid', value: index.toString())
        .then((_) => true);
  }

  // 获取用于头像更新的index
  Future<int> getAvatarUpdateIndex(String uid) {
    return _storage.read(key: '${_avatarUpdateIndex}_$uid').then((index) {
      return index != null ? int.parse(index) : 0;
    });
  }
}
